﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Net;

public partial class Modules_DienThoaiEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            loaddspb();
        }
        
      //  string hostname = "";
       // IPAddress ip =IPAddress.Parse(Request.UserHostName.ToString());
       // hostname = Request.UserHostName;
     //   Response.Write(hostname);
     //   Response.Write(Dns.GetHostByAddress(ip).ToString());

    }
      


    private void loaddspb()
    {
        PhongBan pb = new PhongBan();
        DataTable dt =pb.LoadDanhSachPhongBan();
        dropdownPB.DataSource = dt;
        dropdownPB.DataValueField = "MaPhong";
        dropdownPB.DataTextField="TenPhong";
        dropdownPB.DataBind();
    }
    protected void Xem_Click(object sender, EventArgs e)
    {
        NhanVien nv = new NhanVien();
        nv.Phg=int.Parse(dropdownPB.SelectedValue.ToString());
        gridItem.DataSource = nv.LoadDanhSachNhanVienThuocPhong();
        gridItem.DataBind();
        btnExport.Visible = true;

    }
    protected void gridItem_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gridItem.PageIndex = e.NewPageIndex;
        Xem_Click(null, null);
    }
  
    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "application/ms-excel";
        Response.Charset = "";
        Page.EnableViewState = false;
        Response.AddHeader("Content-Disposition", "inline;filename=Telephone.xls");

        System.IO.StringWriter tw = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

        gridItem.RenderControl(hw);

        Response.Write(tw.ToString());
        Response.End();
    }
    public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
    {
        //confirms that an HtmlForm control is rendered for the
        //specified ASP.NET server control at run time.
    }
}